// 书写属性相关的API文件
import request from '@/utils/request'
import type { CategoryResponseData, AttrResponseData, Attr } from './type'

enum API {
  C1_URL = '/admin/product/getCategory1',
  C2_URL = '/admin/product/getCategory2/',
  C3_URL = '/admin/product/getCategory3/',
  ATTR_URL = '/admin/product/attrInfoList/',
  // 添加或者修改已有的属性的接口
  ADDORUPDATEATTR_URL = '/admin/product/saveAttrInfo',
  // 删除某一个已有属性的接口
  DELETEATTR_URL = '/admin/product/deleteAttr/',
}

// 一级分类接口  GET /admin/product/getCategory1
export const reqC1 = () => request.get<any, CategoryResponseData>(API.C1_URL)

// 二级分类的接口  GET /admin/product/getCategory2/{category1Id}
export const reqC2 = (category1Id: number | string) =>
  request.get<any, CategoryResponseData>(API.C2_URL + category1Id)

// 三级分类的接口  GET /admin/product/getCategory3/{category2Id}
export const reqC3 = (category2Id: number | string) =>
  request.get<any, CategoryResponseData>(API.C3_URL + category2Id)

// 获取分类下已有的属性与属性值  GET /admin/product/attrInfoList/{category1Id}/{category2Id}/{category3Id}
export const reqAttr = (
  category1Id: string | number,
  category2Id: string | number,
  category3Id: string | number,
) =>
  request.get<any, AttrResponseData>(
    API.ATTR_URL + `${category1Id}/${category2Id}/${category3Id}`,
  )

// 添加或者修改已有的属性的接口   POST /admin/product/saveAttrInfo
export const reqAddOrUpdateAttr = (data: Attr) =>
  request.post<any, any>(API.ADDORUPDATEATTR_URL, data)

// 删除已有属性的接口  DELETE /admin/product/deleteAttr/{attrId}
export const reqRemoveAttr = (attrId: number) =>
  request.delete<any, any>(API.DELETEATTR_URL + attrId)
